﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using Ccit.Utils;

namespace Ccit.OA.NewsCenter
{
    public partial class news_window_list : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack){

                _hidTabId.Value =( null != Request.QueryString["TABID"]) ? Request.QueryString["TABID"].ToString() : "";
                
                _hidType.Value=(null != Request.QueryString["Type"]) ? Request.QueryString["Type"].ToString() : "0";
            }
            initializePage();
        }
        private void initializePage()
        {
            WindowBLL bll = new WindowBLL();
            string winName = txtWinName.Value;
            gvWindowList.DataSource = bll.GetWindowList(winName,_hidType.Value);
            gvWindowList.DataBind();
        }

        protected void lnbSearch_Click(object sender, EventArgs e)
        {
            initializePage();
        }

        protected void gvWindowList_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
        {
            if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
            string plateId = e.KeyValue.ToString();
            string showNum = gvWindowList.GetRowValues(e.VisibleIndex, "ShowNum").ToString();
            string showCreator = gvWindowList.GetRowValues(e.VisibleIndex, "ShowCreateor").ToString();
            string showPubTime = gvWindowList.GetRowValues(e.VisibleIndex, "ShowPubTime").ToString();
            if (showNum=="0")
                e.Row.Cells[2].Text="显示全部";
            if (showCreator=="0")
                e.Row.Cells[3].Text="不显示";
            if(showCreator=="1")
                e.Row.Cells[3].Text = "显示";
            if(showPubTime=="0")
                e.Row.Cells[4].Text="不显示";
            if(showPubTime=="1")
                e.Row.Cells[4].Text="显示";
            HtmlAnchor haEdit = (HtmlAnchor)gvWindowList.FindRowCellTemplateControl(e.VisibleIndex, null, "aEdit");
            HtmlAnchor haDel = (HtmlAnchor)gvWindowList.FindRowCellTemplateControl(e.VisibleIndex, null, "aDel");

            string sPageParam = "plateId=" + plateId + "&Type=" + _hidType.Value+"&TABID="+_hidTabId.Value;
            string encodeParam = base64encode(sPageParam);

            haEdit.Attributes["href"] = "news_window_frame.aspx?" + encodeParam;
            haDel.Attributes["href"] = "javascript:doRemove('"+plateId+"')";


            e.Row.Cells[0].Text =( e.VisibleIndex + 1).ToString();
        }
        private string base64encode(string sPageParam)
        {
            string encodeParam = string.Empty;
            if (string.IsNullOrEmpty(sPageParam)) return encodeParam;

            encodeParam = Base64Lib.Encode(sPageParam);
            return encodeParam;
        }

        /// <summary>
        /// 删除操作
        /// </summary>
        /// <param name="plateId">NEWS_B2_10</param>
        /// <returns></returns>
        [global::System.Web.Services.WebMethod]
        public static string RemovePlate(string plateId,string Type)
        {
            WindowBLL bll=new WindowBLL();
            List<string> slist = bll.RemoveWinStyle(plateId,Type);
            var oResult = new { resFlag=slist[0],resMes=slist[1] };
            return JavaScriptConvert.SerializeObject(oResult);
        }
    }
}
